<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单号" prop="orderId">
        <el-input v-model="queryParams.orderId" placeholder="请输入订单号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    <div  style="height: 750px;">
      <div style="height: 80%;">
        <el-table v-loading="loading" :data="ordersaleList" @selection-change="handleSelectionChange" border>
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="id" align="center" prop="orderSaleId" /> -->
           <el-table-column label="销售时间" align="center" prop="createTime" />
          <el-table-column label="订单号" align="center" prop="orderId" />
               <el-table-column label="销售业绩教师" align="center" prop="orderSaleTeacher" />
          <el-table-column label="销售总额(元)" align="center" prop="orderSaleAllmoney" />

          <el-table-column label="销售业绩比例%" align="center" prop="orderSaleProportion" />
          <el-table-column label="销售业绩金额(元)" align="center" prop="orderSaleMoney" />



        </el-table>

      </div>
      <div>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getList" />
      </div>
    </div>





    <!-- 添加或修改订单销售对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!--  <el-form-item label="订单id" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单id" />
        </el-form-item> -->
        <el-form-item label="销售总额" prop="orderSaleAllmoney">
          <el-input v-model="form.orderSaleAllmoney" placeholder="请输入销售总额" />
        </el-form-item>
        <el-form-item label="销售教师" prop="orderSaleTeacher">
          <el-input v-model="form.orderSaleTeacher" placeholder="请输入销售业绩教师" />
        </el-form-item>
        <el-form-item label="销售比例" prop="orderSaleProportion">
          <el-input v-model="form.orderSaleProportion" placeholder="请输入销售业绩比例" />
        </el-form-item>
        <el-form-item label="销售金额" prop="orderSaleMoney">
          <el-input v-model="form.orderSaleMoney" placeholder="请输入销售业绩金额" />
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listOrdersale,
    getOrdersale,
    delOrdersale,
    addOrdersale,
    updateOrdersale
  } from "@/api/ordersale/ordersale";

  export default {
    name: "Ordersale",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 订单销售表格数据
        ordersaleList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderId: null,
          orderSaleAllmoney: null,
          orderSaleTeacher: null,
          orderSaleProportion: null,
          orderSaleMoney: null,
          deptId: null,
          remark2: null,
          remark3: null,
          remark4: null,
          remark5: null,
          remark6: null,
          remark7: null,
          remark8: null,
          remark9: null,
          remark10: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询订单销售列表 */
      getList() {
        this.loading = true;
        this.queryParams.deptId = this.$store.state.user.deptId;
        listOrdersale(this.queryParams).then(response => {
          this.ordersaleList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          orderSaleId: null,
          orderId: null,
          orderSaleAllmoney: null,
          orderSaleTeacher: null,
          orderSaleProportion: null,
          orderSaleMoney: null,
          deptId: null,
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          remark2: null,
          remark3: null,
          remark4: null,
          remark5: null,
          remark6: null,
          remark7: null,
          remark8: null,
          remark9: null,
          remark10: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.orderSaleId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加订单销售";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const orderSaleId = row.orderSaleId || this.ids
        getOrdersale(orderSaleId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改订单销售";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.orderSaleId != null) {
              updateOrdersale(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addOrdersale(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const orderSaleIds = row.orderSaleId || this.ids;
        this.$modal.confirm('是否确认删除订单销售编号为"' + orderSaleIds + '"的数据项？').then(function() {
          return delOrdersale(orderSaleIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('ordersale/ordersale/export', {
          ...this.queryParams
        }, `ordersale_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
